package com.mjh.controller;

import com.github.pagehelper.PageInfo;
import com.mjh.bean.ClueRemark;
import com.mjh.model.R;
import com.mjh.service.ClueRemarkService;
import com.mjh.vo.ClueRemarkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/clue/remark")
public class ClueRemarkController {
    @Autowired
    private ClueRemarkService clueRemarkService;
    /**
     * 根据线索标识分页查询线索备注列表
     * @param current
     * @param size
     * @param clueId
     * @return
     */
    @GetMapping("/page")
    public R<PageInfo<ClueRemarkVo>> loadClueRemarkPage(@RequestParam Integer current,
                                                        @RequestParam(required = false, defaultValue = "10") Integer size,
                                                        @RequestParam Integer clueId) {
        PageInfo<ClueRemarkVo> pageInfo = clueRemarkService.queryClueRemarkListByPage(current, size, clueId);
        return R.OK(pageInfo);
    }
    /**
     * 新增线索备注
     * @param clueRemark
     * @return
     */
    @PostMapping
    public R<String> saveClueRemark(@RequestBody ClueRemark clueRemark) {
        Boolean saved = clueRemarkService.saveClueRemark(clueRemark);
        return R.HANDLER(saved);
    }

    /**
     * 根据标识查询线索备注信息
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public R<ClueRemark> loadClueRemarkInfo(@PathVariable Integer id) {
        ClueRemark clueRemark = clueRemarkService.queryClueRemarkInfoById(id);
        return R.OK(clueRemark);
    }

    /**
     * 修改线索备注
     * @param clueRemark
     * @return
     */
    @PutMapping
    public R<String> modifyClueRemark(@RequestBody ClueRemark clueRemark) {
        Boolean modified = clueRemarkService.modifyClueRemark(clueRemark);
        return R.HANDLER(modified);
    }
    /**
     * 根据标识删除线索备注
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R<String> removeClueRemarkById(@PathVariable Integer id) {
        Boolean removed = clueRemarkService.removeClueRemarkById(id);
        return R.HANDLER(removed);
    }
}
